/**
 * 版权所有 @鸿名物联 
 * 未经授权，禁止侵权和商业，违法必究
 * 联系QQ：2224313811 
 * 
 */
package com.lp.mqtt;

import com.lp.cache.CacheName;
import com.lp.cache.ProCacheUtil;
import com.lp.mqtt.protocol.ProtocalFactory;
import com.lp.util.LogUtil;
import com.lp.util.ObjectUtil;

public class MessageHandler implements Runnable {
	
	private String message ;
	private String topic ;
	private byte[] msg ;
	
	public MessageHandler(byte[] msg , String message,String topic){
		this.message = message ;
		this.topic = topic;
		this.msg= msg;
	}
	
	@Override
	public void run() {
		try{
			if(topic.contains("/sys/update")){
				// 系统消息
				String[] tmp = topic.split("/");
				String type_value = tmp[3]+ "_"+ message ;
				String value = ProCacheUtil.getCache(CacheName.SCENE_IPDATE_FLAG , type_value );
				if( ObjectUtil.isEmpty(value) ){
					ProCacheUtil.addCache(CacheName.SCENE_IPDATE_FLAG ,type_value, message );
				}
			}
			else if( topic.contains("/dev/coo") ){
				// 小名智能协议
				ProtocalFactory.getInstance("ProtocalMing").analysisData(topic, msg, message);
			}
		}catch(Exception e){
			LogUtil.errorLog(e);
		}
	}
}
